﻿using Paas.Core.Const.Enums.Approvals;
using Basefr.Attributes;
using Basefr.Core.Entities;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;

namespace Paas.Core.Approvals.Entities
{
    /// <summary>
    /// 审批流程模板
    /// </summary>
    [MainTable(nameof(ApproveTemplate))]
    public class ApproveTemplate : EntityBase
    {
        /// <summary>
        /// 审批类型
        /// </summary>
        public EnumApproveType Type { get; set; }

        /// <summary>
        /// 审批流程节点
        /// </summary>
        public virtual List<ApproveTemplateStep> Steps { get; set; }

        [NotMapped]
        public ApproveTemplateStep FirstStep => Steps?.FirstOrDefault(s => Steps.All(st => st.NextId != s.Id));

        public bool IsSecondStep(ApproveTemplateStep step)
        {
            return FirstStep?.NextId == step.Id;
        }

    }
}

